﻿using System;

namespace Red.Toolkit.EngineLogsViewer.Data
{
    // this enumeration type is copied from engine code for better communication
    // !!! order is crucial !!!
    public enum SeverityLevel
    {
        Fatal,      // asserts and fatal errors are logged here
        Error,      // errors and normal asserts are logged here
        Warning,    // warnings
        Info,       // non warning information (DEFAULT)
        Debug,      // non essential debugging information
        Trace,		// total spam

        Unknown,    // additional state when received severity level is unknown on the editor side - it not exists in engine code
        All         // additional state when user want to show all logs - it not exists in engine code
    }

    public class EngineLogAbstractEntry
    {
        #region Data

        public SeverityLevel Severity { get; set; }
        public DateTime Timestamp { get; set; }
        public string Category { get; set; }
        public uint ThreadId { get; set; }
        public string Text { get; set; }

        #endregion

        #region Data - visibility

        public bool IsThreadIdVisible { get; protected set; }
        public bool IsCategoryVisible { get; protected set; }
        public bool IsSeverityVisible { get; protected set; }
        public bool IsTextVisible { get; protected set; }

        #endregion

        #region Constructor

        public EngineLogAbstractEntry()
        {
            IsThreadIdVisible = true;
            IsCategoryVisible = true;
            IsSeverityVisible = true;
            IsTextVisible = true;
        }

        #endregion

        #region Public Methods

        public virtual void SetSeverityFilter( SeverityLevel severityFilter )
        {
            if ( severityFilter == SeverityLevel.All )
            {
                IsSeverityVisible = true;
                return;
            }
            IsSeverityVisible = ( Severity == severityFilter );
        }

        public virtual void SetThreadIdFilter( string threadIdFilter )
        {
            if ( threadIdFilter == "All" )
            {
                IsThreadIdVisible = true;
                return;
            }
            IsThreadIdVisible = ( ThreadId == int.Parse( threadIdFilter ) );
        }

        public virtual void SetCategoryFilter( string categoryFilter )
        {
            IsCategoryVisible = ( Category == categoryFilter ) || ( categoryFilter == "All" );
        }

        public virtual void SetTextFilter( string textFilter )
        {
            if ( textFilter == null || textFilter.Length == 0 )
            {
                IsTextVisible = true;
                return;
            }
            IsTextVisible = Text.Contains( textFilter );
        }

        #endregion
    }
}
